home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / rwvector.lha / RWVector2.1 / src / testmath.cc < prev    next >
C/C++ Source or Header  |  1989-08-18  |  1KB  |  60 lines

  1. /*
  2.  *    Test math functions
  3.  *
  4.  *    Copyright (C) 1988, 1989.
  5.  *
  6.  *    Dr. Thomas Keffer
  7.  *    Rogue Wave Associates
  8.  *    P.O. Box 85341
  9.  *    Seattle WA 98145-1341
  10.  *
  11.  *    Permission to use, copy, modify, and distribute this
  12.  *    software and its documentation for any purpose and
  13.  *    without fee is hereby granted, provided that the
  14.  *    above copyright notice appear in all copies and that
  15.  *    both that copyright notice and this permission notice
  16.  *    appear in supporting documentation.
  17.  *    
  18.  *    This software is provided "as is" without any
  19.  *    expressed or implied warranty.
  20.  *
  21.  *
  22.  *    @(#)testmath.cc    2.1    8/18/89
  23.  */
  24.  
  25.  
  26. #include "rw/DComplexVec.h"
  27.  
  28. #define ORDER 10
  29.  
  30. void checkroots(const DComplexVec&);
  31.  
  32. main()
  33. {
  34.   cout << "Testing roots of one.\n";
  35.   cout << "Check values should be within machine precision of Complex(1,0).\n";
  36.   cout << "\n***** Roots of one of order " << ORDER<<NL;
  37.   DComplexVec plusroots = rootsOfOne(ORDER);
  38.   checkroots(plusroots);
  39.  
  40.   cout << "\n***** Roots of one of order " << -ORDER<<NL;
  41.   DComplexVec minusroots = rootsOfOne(-ORDER);
  42.   checkroots(minusroots);
  43.  
  44.   cout << "\n***** Program should now exit with error.\n";
  45.   DComplexVec impossible = rootsOfOne(0);
  46. }
  47.  
  48. void
  49. checkroots(const DComplexVec& roots)
  50. {
  51.   int order = roots.length();
  52.  
  53.   // Check each root
  54.   for(int i = 0; i < order; i++){
  55.     DComplex prod = pow(roots(i), order);
  56.     cout << "Root " << i << ": " << roots(i) <<
  57.       "; Check value: "<<prod<<NL;
  58.   }
  59. }
  60.